package com.heima.wemedia.inteceptor;

import com.heima.utils.common.threadUtil.ThreadLocalUtil;
import com.heima.utils.common.threadUtil.UserInfo;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.stereotype.Component;

//feign拦截器,将用户id设置进feign请求中
@Component
public class FeignHeaderInteceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        UserInfo userInfo = ThreadLocalUtil.get();

        if(userInfo!=null){
            requestTemplate.header("userId",userInfo.getId().toString());
        }
    }
}
